from datetime import time

from django.shortcuts import render

# Create your views here.
import json
import requests
from django.http import HttpResponse, JsonResponse


class Dict(dict):
    __setattr__ = dict.__setitem__
    __getattr__ = dict.__getitem__


def dictToObj(dictObj):
    if not isinstance(dictObj, dict):
        return dictObj
    d = Dict()
    for k, v in dictObj.items():
        d[k] = dictToObj(v)
    return d


def index(request):
    result = []
    devops_json = requests.get('http://yunzhi.devops.svc.cluster.local/devops/')
    if devops_json is not None:
        devops = json.loads(devops_json.content)  # 根据字符串书写格式，将字符串自动转换成 字典类型
        for data in devops['data']:
            result.append(dictToObj(data))
    return render(request, 'index.html', {"devops": result})
